/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode(int x) : val(x), next(NULL) {}
 * };
 */
class Solution {
public:
    set<int> mp;
    void del(ListNode* &pre, ListNode* &u)
    {
        pre->next=u->next;
        u->next=nullptr;
        u=pre;
    }
    
    ListNode* filterList(ListNode* head) {
        ListNode *pre=head, *u=head; 
        mp.insert(abs(u->val));
        if(u->next) u=head->next;
        while(u)
        {
            if(mp.find(abs(u->val))!=mp.end()) del(pre, u); //节点重复
            else mp.insert(abs(u->val)); //记录当前值
            pre=u;
            u=u->next;
            // pre=pre->next;
        }
        return head;
    }
};